package com.spvs.approval.support.callBack;

import com.spvs.approval.domain.ApprovalFromEntity;
import com.spvs.approval.support.ApprovalBusinessCall;
import com.spvs.approval.support.ApprovalBusinessContext;
import com.spvs.system.api.IPurchaseService;
import com.spvs.system.api.domain.PurchaseCallBackAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 到货审批回调
 */
@Component
public class DHBusinessCallBack implements ApprovalBusinessCall {

    @Autowired
    private IPurchaseService purchaseService;

    @Override
    public Boolean isCall(String type) {
        return ApprovalBusinessContext.TYPE_DH.equals(type);
    }

    @Override
    public void callback(ApprovalFromEntity from, Integer userSort,Long userId) {
        PurchaseCallBackAPI purchaseCallBackAPI = new PurchaseCallBackAPI();
        purchaseCallBackAPI.setId(from.getBusinessId());
        purchaseCallBackAPI.setPurchaseType(2L);
        Integer state = 0;
        switch (from.getStatus()){
            case 101:
                state = 1;
                break;
            case 201:
                state = 2;
                break;
            case 301:
                state = 3;
                break;
            case 302:
                state = 4;
                break;
        }
        purchaseCallBackAPI.setAuditStatus(state);
        purchaseService.callBack(purchaseCallBackAPI);
    }
}
